package UDP;

import java.net.*;

//客户端
public class test {
    public static void main(String[] args) {
        DatagramSocket datagramSocket =null;
        try {
            //1.创建Socket套接字
            datagramSocket = new DatagramSocket();
            //1.1给定IP地址和端口
            InetAddress ip = InetAddress.getByName("127.0.0.1");//IP
            int port = 8080;//端口
            //1.2准备数据
            String xx = "我是谁，我再了，我是客户端";
            //2.创建包
            DatagramPacket Packet = new DatagramPacket(xx.getBytes(),0,xx.getBytes().length,ip,port);
            //3.发送包
            datagramSocket.send(Packet);

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (datagramSocket!=null){
                datagramSocket.close();
            }
        }
    }
}
